﻿using Zero;

/// <summary>
/// 元素反应：融化
/// </summary>
public class ElementMelt : IElementReaction
{
    private readonly IElementHolder _holder;

    public ElementMelt(IElementHolder holder)
    {
        _holder = holder;
    }

    public void Reaction(TriggerElementData triggerElementData)
    {
        if (triggerElementData.ElementType == ElementType.Ice)
        {
            var fireAura = _holder.GetGeneralElementAura(ElementType.Fire);
            if (fireAura.Gauge > 0f)
            {
                var cost = triggerElementData.Gauge * 0.5f;
                triggerElementData.Gauge -= fireAura.Gauge * 2f;
                fireAura.UseGauge(cost);
                triggerElementData.DamageBoosters.Add(new ElementDamageBooster("融化", 1.5f));
                triggerElementData.IsTriggered = true;
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "融化");
                return;
            }
        }

        if (triggerElementData.ElementType == ElementType.Fire)
        {
            var iceAura = _holder.GetGeneralElementAura(ElementType.Ice);
            if (iceAura.Gauge > 0f)
            {
                var cost = triggerElementData.Gauge * 2f;
                triggerElementData.Gauge -= iceAura.Gauge * 0.5f;
                iceAura.UseGauge(cost);
                triggerElementData.DamageBoosters.Add(new ElementDamageBooster("融化", 2f));
                triggerElementData.IsTriggered = true;
                ServiceLocator.Get<IWorldNumberService>()
                    .CreateElementReaction(_holder.Owner.transform.position, "融化");
            }
        }
    }
}